render: Make gtk_render_icon() use the snapshot API
authorBenjamin Otte <otte@redhat.com>
Tue, 24 Jul 2018 18:23:20 +0000 (20:23 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 24 Jul 2018 18:55:45 +0000 (20:55 +0200)
This removes a lot of duplicated code.

gtk/gtkrender.c
gtk/gtkrendericon.c
gtk/gtkrendericonprivate.h

index 8870518cfa51de185e9dff77cde92afad1909f97..4162812dc5da4c4bfad33893b4ea076b742d226a 100644 (file)
@@ -629,17 +629,21 @@ gtk_render_icon (GtkStyleContext *context,
                  gdouble          x,
                  gdouble          y)
 {
-  cairo_surface_t *surface;
-
-  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
-  g_return_if_fail (cr != NULL);
-
-  surface = gdk_texture_download_surface (texture);
+  GtkSnapshot *snapshot;
+  GskRenderNode *node;
 
-  gtk_css_style_render_icon_surface (gtk_style_context_lookup_style (context),
-                                     cr,
-                                     surface,
-                                     x, y);
+  snapshot = gtk_snapshot_new ();
+  gtk_css_style_snapshot_icon_paintable (gtk_style_context_lookup_style (context),
+                                         snapshot,
+                                         GDK_PAINTABLE (texture),
+                                         x, y,
+                                         FALSE);
+  node = gtk_snapshot_free_to_node (snapshot);
+  if (node == NULL)
+    return;
 
-  cairo_surface_destroy (surface);
+  cairo_save (cr);
+  cairo_translate (cr, x, y);
+  gsk_render_node_draw (node, cr);
+  cairo_restore (cr);
 }
index 5a6be7510f2f7756c1915ef8767acbd587ed4be7..2d2dfa05f5213f0a7ac7d06dc2ea9fb784a7a35d 100644 (file)
@@ -96,81 +96,6 @@ gtk_css_style_snapshot_icon (GtkCssStyle            *style,
   gtk_snapshot_pop (snapshot);
 }
 
-static gboolean
-get_surface_extents (cairo_surface_t *surface,
-                     GdkRectangle    *out_extents)
-{
-  cairo_t *cr;
-  gboolean result;
-
-  cr = cairo_create (surface);
-  result = gdk_cairo_get_clip_rectangle (cr, out_extents);
-  cairo_destroy (cr);
-
-  return result;
-}
-
-void
-gtk_css_style_render_icon_surface (GtkCssStyle            *style,
-                                   cairo_t                *cr,
-                                   cairo_surface_t        *surface,
-                                   double                  x,
-                                   double                  y)
-{
-  const GtkCssValue *shadows;
-  graphene_matrix_t graphene_matrix;
-  cairo_matrix_t matrix, transform_matrix, saved_matrix;
-  GdkRectangle extents;
-
-  g_return_if_fail (GTK_IS_CSS_STYLE (style));
-  g_return_if_fail (cr != NULL);
-  g_return_if_fail (surface != NULL);
-
-  shadows = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SHADOW);
-
-  if (!get_surface_extents (surface, &extents))
-    {
-      /* weird infinite surface, no special magic for you */
-      cairo_set_source_surface (cr, surface, x, y);
-      _gtk_css_shadows_value_paint_icon (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SHADOW), cr);
-      cairo_paint (cr);
-      return;
-    }
-
-  cairo_get_matrix (cr, &saved_matrix);
-  cairo_translate (cr, x + extents.x, y + extents.y);
-
-  if (gtk_css_transform_value_get_matrix (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_TRANSFORM), &graphene_matrix) &&
-      graphene_matrix_is_2d (&graphene_matrix))
-    {
-      cairo_pattern_t *pattern;
-
-      graphene_matrix_to_2d (&graphene_matrix,
-                             &transform_matrix.xx, &transform_matrix.yx,
-                             &transform_matrix.xy, &transform_matrix.yy,
-                             &transform_matrix.x0, &transform_matrix.y0);
-      /* XXX: Implement -gtk-icon-transform-origin instead of hardcoding "50% 50%" here */
-      cairo_matrix_init_translate (&matrix, extents.width / 2, extents.height / 2);
-      cairo_matrix_multiply (&matrix, &transform_matrix, &matrix);
-      cairo_matrix_translate (&matrix, - extents.width / 2, - extents.height / 2);
-      if (cairo_matrix_invert (&matrix) != CAIRO_STATUS_SUCCESS)
-        {
-          g_assert_not_reached ();
-        }
-      cairo_matrix_translate (&matrix, extents.x, extents.y);
-
-      pattern = cairo_pattern_create_for_surface (surface);
-      cairo_pattern_set_matrix (pattern, &matrix);
-      cairo_set_source (cr, pattern);
-      cairo_pattern_destroy (pattern);
-
-      _gtk_css_shadows_value_paint_icon (shadows, cr);
-      cairo_paint (cr);
-    }
-
-  cairo_set_matrix (cr, &saved_matrix);
-}
-
 void
 gtk_css_style_snapshot_icon_paintable (GtkCssStyle  *style,
                                        GtkSnapshot  *snapshot,
index 4cb7628349890df3a6a7f3fc3df2342d741653e6..1514d295bd16afc01c510f003e9e95c384096a9f 100644 (file)
@@ -35,11 +35,6 @@ void    gtk_css_style_snapshot_icon             (GtkCssStyle            *style,
                                                  double                  height,
                                                  GtkCssImageBuiltinType  builtin_type);
 
-void    gtk_css_style_render_icon_surface       (GtkCssStyle            *style,
-                                                 cairo_t                *cr,
-                                                 cairo_surface_t        *surface,
-                                                 double                  x,
-                                                 double                  y);
 void    gtk_css_style_snapshot_icon_paintable   (GtkCssStyle            *style,
                                                  GtkSnapshot            *snapshot,
                                                  GdkPaintable           *paintable,